package org.coderjonny.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.coderjonny.constant.HttpCode;
import org.coderjonny.trace.TraceIdUtil;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1497405107265595284L;
    private Integer code;
    private T data;
    private String msg;
    private String traceId = TraceIdUtil.getNowTraceId();

    public static<T> Result<T> ok(T data){
        Result<T> result = new Result<>();
        result.setCode(HttpCode.SUCCESS);
        result.setData(data);
        return result;
    }

    public static<T> Result<T> error(String msg){
        Result<T> result = new Result<>();
        result.setCode(HttpCode.FAILURE);
        result.setMsg(msg);
        return result;
    }
}
